//package com.mask.sca.system.filter;
//
//import com.mask.sca.core.tenant.TenantContext;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//
//@Component
//@ConditionalOnProperty(prefix = "mask.tenant", name = "enabled", havingValue = "true", matchIfMissing = true)
//public class TenantFilter implements Filter {
//    private static final String TENANT_HEADER = "X-Tenant-Id";
//
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//        HttpServletRequest httpRequest = (HttpServletRequest) request;
//        String tenantId = httpRequest.getHeader(TENANT_HEADER);
//        // 预留：可从Token等其他方式获取租户ID
//        // if (tenantId == null) {
//        //     String token = httpRequest.getHeader("Authorization");
//        //     // 解析token获取租户ID（如JWT）
//        //     // tenantId = JwtUtil.parseTenantId(token);
//        // }
//        if (tenantId != null) {
//            TenantContext.setTenantId(tenantId);
//        }
//        try {
//            chain.doFilter(request, response);
//        } finally {
//            TenantContext.clear();
//        }
//    }
//}